package cn.szbo.jksystem.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.szbo.jksystem.core.GenericServiceImpl;
import cn.szbo.jksystem.dao.UserDao;
import cn.szbo.jksystem.model.User;
import cn.szbo.jksystem.service.UserService;

/**
 * @author nick xue
 * 
 *         2012-7-22 下午1:41:08
 */
@Service(value = "userService")
public class UserServiceImpl extends GenericServiceImpl<User> implements
		UserService {

	@Autowired
	private UserDao userDao;

	@Override
	protected UserDao getGenericDao() {
		return this.userDao;
	}

	public User findUser(String loginId, String password) {

		if (StringUtils.isEmpty(loginId) || StringUtils.isEmpty(password)) {
			return null;
		}

		Object o = userDao.selectUser(loginId, password);

		if (null != o) {
			return (User) o;
		} else {
			return null;
		}
	}

	public List<Map<String, Object>> findUsers() {
		return userDao.selectUsers();
	}

	public User findUserByLoginId(String loginId) {
		return userDao.selectUserByLoginId(loginId);
	}

	public void addUser(User user) {
        userDao.insertUser(user);
    }

}
